package com.leetcode;

public class Test_2 {
    public static void main(String[] args) {


    }
}




 class ListNode {
     int val;
     ListNode next;

     ListNode() {
         ;
     }

     ListNode(int val) {
         this.val = val;
     }

     ListNode(int val, ListNode next) {
         this.val = val;
         this.next = next;
     }
 }

     class S {
         public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
             int sum1 = 0;
             ListNode cur = l1;
             int ten = 0;//表示10的指数
             while (cur != null) {//得到l1的实际值
                 int tem = 1;
                 while (ten-- > 0) {
                     tem *= 10;
                 }
                 sum1 += cur.val * tem;
                 cur = cur.next;
                 ten++;//每取一个值,10的指数就加一
             }
             int sum2 = 0;
             ListNode cur2 = l2;
             ten = 0;
             while (cur2 != null) {//得到l2的实际值
                 int tem = 1;
                 while (ten-- > 0) {
                     tem *= 10;
                 }
                 sum2 += cur2.val * tem;
                 cur2 = cur2.next;
                 ten++;
             }

             //相加
             int sum = sum1 + sum2;
             //将sum制作成链表返回
             ListNode ret = new ListNode();
             ListNode retsum = ret;
             while (sum > 0) {//尾插123
                 ListNode newNode = new ListNode(sum % 10);
                 ret.next = newNode;
                 ret = newNode;
                 sum /= 10;
             }
             return retsum;
         }
     }
